package com.offcn.sms.listener;

import com.offcn.sms.utils.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    /**
     *
     * @param map  接收两个值 phone 和 code
     */
    @RabbitListener(queues = "dongyimai.sms.queue")
    public void getMessage(Map<String,String> map){
        if (map == null) {
            return;  // 结束方法
        }
        String phone = map.get("phone");
        String code = map.get("code");
        // 短信发送
        smsUtil.sendSms(phone,code);

    }
}
